package com.syty.demo.config;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Api("Swagger-配置类")
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean(value = "swaggerRestApi")
    public Docket swaggerRestApi(Environment environment) {

        // 要显示的Swagger环境
        Profiles dev = Profiles.of("dev","test");
        // 判断是否在自己的环境中
        boolean flag = environment.acceptsProfiles(dev);

        ApiInfo  apiInfo= new ApiInfoBuilder()
                .title("接口文档")
                .description("接口文档")
                .version("1.0.0")
                .contact(new Contact("syty","https://xxx.com","123123123@qq.com"))
                .license("Apache 2.0")
                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
                .build();

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.du.controller"))
                .paths(PathSelectors.any())
                .build()
                .groupName("接口文档")
                .apiInfo(apiInfo)
                .enable(flag);
    }
}


